//  Android Carpool System
//  2011-2011
//  Author: Jinhuan Wang
//  name: Signin.java
//  description: provide method to sign up 
//$history: /carpool/scr/com/DataExange/Signup.java$
package com.carpool.message;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class Signup {
	private static final String SERVLET_URL = "http://169.254.80.238:8080/carpooletservice/Signup";
	 static boolean success;
	public static boolean signup(String name,String password,String phone){
		URL url = null;
		HttpURLConnection httpurlconnection = null;
		try {
			url = new URL(SERVLET_URL);
			httpurlconnection = (HttpURLConnection) url.openConnection();
			httpurlconnection.setRequestMethod("POST");
			httpurlconnection.setDoOutput(true);
			httpurlconnection.setDoInput(true);
			httpurlconnection.connect();
			DataOutputStream dos = new DataOutputStream(
					httpurlconnection.getOutputStream());
			dos.writeUTF(name);
			dos.writeUTF(password);
			dos.writeUTF(phone);
			
			dos.flush();
			dos.close();
			DataInputStream dis = new DataInputStream(
					httpurlconnection.getInputStream());
			success = dis.readBoolean();
		} catch (Exception e) {
		// e.printStackTrace();
		success = false;

	} finally {
		if (httpurlconnection != null)
			httpurlconnection.disconnect();
	}
		return success;
	}

}
